package com.monodaipoly2.view;


import com.google.appengine.api.datastore.Key;
import com.monodaipoly2.persistencia.Calle;
import com.monodaipoly2.persistencia.Rol;
import com.monodaipoly2.servicio.CalleServicio;
import com.monodaipoly2.servicio.RolServicio;
import java.text.SimpleDateFormat;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.stereotype.Component;
import org.springframework.web.jsf.FacesContextUtils;

@Component
public class CalleConverter implements javax.faces.convert.Converter{

    private CalleServicio getCalleServicio(FacesContext context){
        return (CalleServicio)FacesContextUtils.getWebApplicationContext(context).getBean("calleServicio");
    }

    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, Object o) {

        String rdo=null;
        if (o instanceof Key) {
            Key keyCalle = (Key) o;
            Calle calle = getCalleServicio(FacesContext.getCurrentInstance()).buscar(keyCalle);
            
            rdo=calle.getPrecio()+"$";

        }else{
            rdo="Sin precio";
        }
        return rdo;

    }

 

}
